<?php
namespace App\Actions;

use App\Actions\BaseAction;
use App\Models\SmsPool;
use Illuminate\Support\Facades\DB;

class SmsPoolAction extends BaseAction
{
    public $model;
    
    public function __construct(SmsPool $model=null)
    {
        $this->model = $model;
    }

    public function batchInsert($inserts)
    {
        if (count($inserts) > 0) {
            DB::table((new SmsPool())->getTable())->insert($inserts);
        }
    }
    public function pushPool($inputs, $relation_model = null, $relation_type = '')
    {
        try {
            SmsPool::create([
                'gid' => isset($inputs['gid']) ? $inputs['gid'] : null,
                'zjhm' => isset($inputs['zjhm']) ? $inputs['zjhm'] : null,
                'name' => isset($inputs['name']) ? $inputs['name'] : null,
                'email' => isset($inputs['email']) ? $inputs['email'] : null,
                'phone' => isset($inputs['phone']) ? $inputs['phone'] : null,
                'title' => isset($inputs['title']) ? $inputs['title'] : null,
                'content' => isset($inputs['content']) ? $inputs['content'] : null,
                'status' => SmsPool::STATUS_PENDING,
                'type' => isset($inputs['type']) ? $inputs['type'] : SmsPool::TYPE_BY_PHONE,
                'sms_send_at' => null,
                'relation_id' => $relation_model ? $relation_model->id : null,
                'relation_table' => $relation_model ? $relation_model->getTable() : null,
                'relation_type' => $relation_type,
            ]);
        } catch (\Throwable $th) {
            //throw $th;
        }
    }

    /**
     * Create a form instance.
     *
     * @param  mixed  ...$params
     * @return $this
     */
    public static function make(...$params)
    {
        return new static(...$params);
    }
}